#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
    x = 0; int f = 1; char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
    for (; isdigit(c); c = getchar()) x =  (x << 3) + (x << 1) + (c ^ 48);
    x *= f;
}
#define ll long long
const int maxn = 1e6 + 10;
int T, n, m, L, V;
// open the freopen
struct node{
    int d, v, a;
}c[maxn];
int p[maxn], l, r;
int s[maxn];
int ans, cnt;
struct lin{
    int l, r;
}b[maxn];
bool cmp(lin x, lin y){
    if (x.r == y.r) return x.l < y.l;
    return x.r < y.r;
}
int f[maxn];
int lowbit(int x){
    return x & (-x);
}
void Add(int x, int d){
    for (int i = x; i <= m; i += lowbit(i)){
        f[i] += d;
    }
}
int Sum(int x){
    int ret = 0;
    for (int i = x; i > 0; i -= lowbit(i)){
        ret += f[i];
    }
    return ret;
}
void solve(){
        read(n); read(m); read(L); read(V);
        L++;
        for (int i = 1; i <= L; i++) s[i] = 0;
        ans = cnt = 0;
        for (int i = 1; i <= n; i++){
            read(c[i].d); read(c[i].v); read(c[i].a);
            c[i].d++;
        }
        for (int i = 1; i <= m; i++) read(p[i]), f[i] = 0;
        for (int i = 1; i <= m; i++) s[++p[i]]++;
        for (int i = 1; i <= L; i++) s[i] += s[i - 1];
        int t = 0;
        for (int i = 1; i <= n; i++){
            int d = c[i].d, v = c[i].v, a = c[i].a;
            if (v <= V){
                if (a <= 0){
                    continue;
                }else{
                    int l = (int)(1.0 * (V * V - v * v) / 2 / a);
                    if ((ll)2 * a * l <= (ll)(V * V - v * v)) l++;
                    if (s[L] - s[min(L, d + l - 1)]){
                        ans++;
                        b[++t].l = lower_bound(p + 1, p + m + 1, d + l) - p;
                        b[t].r = m;
                    }
                }
            }else{
                if (a < 0){
                    int l = (int)(1.0 * (v * v - V * V) / 2 / (-a));
                    if ((ll)2 * (-a) * l == (ll)(v * v - V * V)) l--;
                    if (s[min(L, d + l)] - s[d - 1]){
                        ans++;
                        b[++t].l = lower_bound(p + 1, p + m + 1, d) - p;
                        b[t].r = upper_bound(p + 1, p + m + 1, d + l) - p - 1;
                    }
                }else{
                    if (s[L] - s[d - 1]){
                        ans++;
                        b[++t].l = lower_bound(p + 1, p + m + 1, d) - p;
                        b[t].r = m;
                    }
                }
            }
        }
        sort(b + 1, b + t + 1, cmp);
        for (int i = 1; i <= t; i++){
            if (Sum(b[i].l) != 0){
                continue;
            }else{
                Add(1, 1);
                Add(b[i].r + 1, -1);
                cnt++;
            }
        }
        printf("%d %d\n", ans, m - cnt);
}
int main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    read(T);
    while (T--){
        solve();
    }
    return 0;
}
